<template>
	<view>
		<view class="goods_list">
			<block v-for="(goods,i) in goodsList" :key="i">
				<view class="goods_item">
					<!-- 左侧盒子 -->
					<view class="goods-item-left">
						<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
					</view>
					<!-- 右侧盒子 -->
					<view class="goods-item-right">
						<!-- 商品名字 -->
						<view class="goods-name">{{goods.goods_name}}</view>
						<view class="goods-info-box">
							<view class="goods-price">￥{{goods.goods_price}}</view>
						</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				//请求参数对象
				queryObj:{
					query: '',
					cid: '',
					pagenum:1,
					pagesize:10
				},
				goodsList:[],
				total:0,
				//默认的图片
				defaultPic:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		onLoad(options) {
		  // 将页面参数转存到 this.queryObj 对象中
		  this.queryObj.query = options.query || ''
		  this.queryObj.cid = options.cid || ''
		  
		  this.getGoodsList()
		},
		methods:{
			//获取商品列表数据的方法
			async getGoodsList(){
				const {data: res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				if (res.meta.status !== 200) return uni.$showMsg()
				
				this.goodsList = res.message.goods
				this.total = res.message.total
			}
		}
	}
</script>

<style lang="scss">
.goods_item{
	display: flex;
	padding: 10px 5px;
	border-bottom: 1px solid #f0f0f0;
	
	.goods-item-left{
		margin-right: 5px;
		
		.goods-pic{
			width: 100px;
			height: 100px;
			display: block;
		}
	}
	
	.goods-item-right{
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		
		
		.goods-name{
			font-size: 13px;
		}
		
		
		.goods-info-box{
			.goods-price{
				color: #c00000;
				font-size: 16px;
			}
		}
	}
}

</style>
